package com.java110.mall.goods.smo.impl;


import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.dto.PageDto;
import com.java110.dto.asset.AssetInventoryDto;
import com.java110.intf.goods.IAssetInventoryInnerServiceSMO;
import com.java110.mall.goods.dao.IAssetInventoryServiceDao;
import com.java110.po.assetInventory.AssetInventoryPo;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName FloorInnerServiceSMOImpl
 * @Description 资产盘点内部服务实现类
 * @Author wuxw
 * @Date 2019/4/24 9:20
 * @Version 1.0
 * add by wuxw 2019/4/24
 **/
@RestController
public class AssetInventoryInnerServiceSMOImpl extends BaseServiceSMO implements IAssetInventoryInnerServiceSMO {

    @Autowired
    private IAssetInventoryServiceDao assetInventoryServiceDaoImpl;


    @Override
    public int saveAssetInventory(@RequestBody AssetInventoryPo assetInventoryPo) {
        int saveFlag = 1;
        assetInventoryServiceDaoImpl.saveAssetInventoryInfo(BeanConvertUtil.beanCovertMap(assetInventoryPo));
        return saveFlag;
    }

    @Override
    public int updateAssetInventory(@RequestBody AssetInventoryPo assetInventoryPo) {
        int saveFlag = 1;
        assetInventoryServiceDaoImpl.updateAssetInventoryInfo(BeanConvertUtil.beanCovertMap(assetInventoryPo));
        return saveFlag;
    }

    @Override
    public int deleteAssetInventory(@RequestBody AssetInventoryPo assetInventoryPo) {
        int saveFlag = 1;
        assetInventoryPo.setStatusCd("1");
        assetInventoryServiceDaoImpl.updateAssetInventoryInfo(BeanConvertUtil.beanCovertMap(assetInventoryPo));
        return saveFlag;
    }

    @Override
    public List<AssetInventoryDto> queryAssetInventorys(@RequestBody AssetInventoryDto assetInventoryDto) {

        //校验是否传了 分页信息

        int page = assetInventoryDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            assetInventoryDto.setPage((page - 1) * assetInventoryDto.getRow());
        }

        List<AssetInventoryDto> assetInventorys = BeanConvertUtil.covertBeanList(assetInventoryServiceDaoImpl.getAssetInventoryInfo(BeanConvertUtil.beanCovertMap(assetInventoryDto)), AssetInventoryDto.class);

        return assetInventorys;
    }


    @Override
    public List<AssetInventoryDto> queryAssetInventoryReports(@RequestBody AssetInventoryDto assetInventoryDto) {

        //校验是否传了 分页信息

        int page = assetInventoryDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            assetInventoryDto.setPage((page - 1) * assetInventoryDto.getRow());
        }

        List<AssetInventoryDto> assetInventorys = BeanConvertUtil.covertBeanList(assetInventoryServiceDaoImpl.queryAssetInventoryReports(BeanConvertUtil.beanCovertMap(assetInventoryDto)), AssetInventoryDto.class);

        return assetInventorys;
    }
    @Override
    public int queryAssetInventorysCount(@RequestBody AssetInventoryDto assetInventoryDto) {
        return assetInventoryServiceDaoImpl.queryAssetInventorysCount(BeanConvertUtil.beanCovertMap(assetInventoryDto));
    }

    public IAssetInventoryServiceDao getAssetInventoryServiceDaoImpl() {
        return assetInventoryServiceDaoImpl;
    }

    public void setAssetInventoryServiceDaoImpl(IAssetInventoryServiceDao assetInventoryServiceDaoImpl) {
        this.assetInventoryServiceDaoImpl = assetInventoryServiceDaoImpl;
    }
}
